package com.ruoyi.instrument.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.instrument.domain.InstrumentData;
import com.ruoyi.instrument.service.IInstrumentDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仪器Controller
 * 
 * @author weihanqiang
 * @date 2025-04-18
 */
@RestController
@RequestMapping("/instrument/data")
public class InstrumentDataController extends BaseController
{
    @Autowired
    private IInstrumentDataService instrumentDataService;

    /**
     * 查询仪器列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(InstrumentData instrumentData)
    {
        startPage();
        List<InstrumentData> list = instrumentDataService.selectInstrumentDataList(instrumentData);
        return getDataTable(list);
    }

    /**
     * 导出仪器列表
     */
    @PreAuthorize("@ss.hasPermi('instrument:data:export')")
    @Log(title = "仪器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InstrumentData instrumentData)
    {
        List<InstrumentData> list = instrumentDataService.selectInstrumentDataList(instrumentData);
        ExcelUtil<InstrumentData> util = new ExcelUtil<InstrumentData>(InstrumentData.class);
        util.exportExcel(response, list, "仪器数据");
    }

    /**
     * 获取仪器详细信息
     */
    @PreAuthorize("@ss.hasPermi('instrument:data:query')")
    @GetMapping(value = "/{instrumentId}")
    public AjaxResult getInfo(@PathVariable("instrumentId") Long instrumentId)
    {
        return success(instrumentDataService.selectInstrumentDataByInstrumentId(instrumentId));
    }

    /**
     * 新增仪器
     */
    @PreAuthorize("@ss.hasPermi('instrument:data:add')")
    @Log(title = "仪器", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InstrumentData instrumentData)
    {
        instrumentData.setCreatorId(getUserId());
        instrumentData.setCreator(getUsername());
        return toAjax(instrumentDataService.insertInstrumentData(instrumentData));
    }

    /**
     * 修改仪器
     */
    @PreAuthorize("@ss.hasPermi('instrument:data:edit')")
    @Log(title = "仪器", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InstrumentData instrumentData)
    {
        instrumentData.setModifierId(getUserId());
        instrumentData.setModifier(getUsername());
        return toAjax(instrumentDataService.updateInstrumentData(instrumentData));
    }

    /**
     * 删除仪器
     */
    @PreAuthorize("@ss.hasPermi('instrument:data:remove')")
    @Log(title = "仪器", businessType = BusinessType.DELETE)
	@DeleteMapping("/{instrumentIds}")
    public AjaxResult remove(@PathVariable Long[] instrumentIds)
    {
        return toAjax(instrumentDataService.deleteInstrumentDataByInstrumentIds(instrumentIds));
    }
}
